const { contextBridge, ipcRenderer } = require('electron');

contextBridge.exposeInMainWorld('clickBtn', {
    clickRegister: () => {
        ipcRenderer.send('window-action', { action: 'click-register' });
    },
    clickLogin: () => {
        ipcRenderer.send('window-action', { action: 'click-login' });
    },
    registerSuccess: (userName,  userId, userToken) => {
        ipcRenderer.send('window-action', { action: 'register-success', userName, userId, userToken });
    },
    openMainWindow: () => {
        ipcRenderer.send('window-action', { action: 'open-main-window' });
    },
    getUserDataObject: async () => {
        try {
            return await ipcRenderer.invoke('get-user-data');
        } catch (error) {
            console.error('Error getting user data:', error);
            throw error;
        }
    }
})

contextBridge.exposeInMainWorld('electronAPI', {
    onUpdateContactList: (callback) => ipcRenderer.on('update-contact-list', (_event, value) => callback(value)),
    getContactList: () => ipcRenderer.send('get-contact-list'),
    openDevTools: () => {
        console.log('发送打开开发者工具请求');
        ipcRenderer.send('open-devtools')
    }
})